package com.igeek.shop.service;

import java.sql.SQLException;

import com.igeek.common.utils.MD5Utils;
import com.igeek.shop.dao.BaseDao;
import com.igeek.shop.entity.User;

public class UserService {
	private BaseDao dao = new BaseDao();

	public boolean regist(User user) {
		
		String password = MD5Utils.md5(user.getPassword());
		String sql = "insert into user values(?,?,?,?,?,?,?,?,?,?,?)";
		Object [] params = {user.getUid(),user.getUsername(),password,
				user.getName(),user.getEmail(),user.getTelephone(),user.getBirthday(),
				user.getSex(),user.getState(),user.getCode(),0};
		int row = dao.update(sql, params);
		return row > 0 ? true : false;
	}

	public boolean active(String activeCode) {
		String sql = "update user set state = 1 where code = ? ";
		Object [] params = {activeCode};
		int row = dao.update(sql, params);
		return row > 0 ? true : false;
		
	}
	public boolean checkUsername(String username) {
		
		Long count = 0L;
		try {
			count = dao.checkUsername(username);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return count>0?true:false;
	}

}
